<?php

/**
 * operator actions.
 *
 * @package    travelbug
 * @subpackage operator
 * @author     David J. Sloan
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class operatorActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    //$this->forward('default', 'module');
    $c = new Criteria();
    $c -> add(operatorTourPeer::USER_ID, $this->getUser()->getGuardUser()->getId());
    $this->operator_tour_list = operatorTourPeer::doSelect($c);
  }
  
  public function executePostTour(sfWebRequest $request)
  {
  	$this->form = new operatorTourForm();
  }
  
  public function executeCreateTour(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));


    $this->form = new operatorTourForm();

    $this->processForm($request, $this->form);

    // $this->redirect('operator/index');
  }
  
  public function executeNewImage(sfWebRequest $request)
  {
     $this->tour_id=$request->getParameter('id');
     $this->form = new operatorTourImagesForm();
    // $this->redirect('http://www.cnn.com');
  }
  public function executeUpload(sfWebRequest $request)
  {
  	$this->forward404Unless($request->isMethod('post'));


    $this->form = new operatorTourImagesForm();

    $this->processForm($request, $this->form);
  //	$this->tour_id=$request->getParameter('tour_id');
   // $fileName = $this->getRequest()->getFileName('file');
 
   // $this->getRequest()->moveFile('file', sfConfig::get('sf_upload_dir').'/'.$fileName);
 
    //$this->redirect('operator/editTour?id='.$this->tour_ud);    
  }
  public function executeEditTour(sfWebRequest $request)
  {
    $this->forward404Unless($operator_tour = operatorTourPeer::retrieveByPk($request->getParameter('id')), sprintf('Object operator_tour does not exist (%s).', $request->getParameter('id')));
    $this->form = new operatorTourForm($operator_tour);
  }
  
  public function executeUpdateTour(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($operator_tour = operatorTourPeer::retrieveByPk($request->getParameter('id')), sprintf('Object operator_tour does not exist (%s).', $request->getParameter('id')));
    $this->form = new operatorTourForm($operator_tour);

    $this->processForm($request, $this->form);

    $this->redirect('operator/index');
  }
  
  public function executeDeleteTour(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($operator_tour = operatorTourPeer::retrieveByPk($request->getParameter('id')), sprintf('Object operator_tour does not exist (%s).', $request->getParameter('id')));
    $operator_tour->delete();

    $this->redirect('operator/index');
  }
  
  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    $operator_tour = $form->save();

      $this->redirect('operator/index?id='.$operator_tour->getId());
    if ($form->isValid())
    {
      $operator_tour = $form->save();

      $this->redirect('operator/index?id='.$operator_tour->getId());
    }
  }
}
